package cn.yunhe.model;

import java.util.List;

public class Pagination<T>{
    private int totalRecords;//总记录数,充要条件
    private int maxRows;//每页显示的最大行数,,充要条件
    private int currPageNo;//当前页码,,充要条件

    private int prePageNo;//上一页
    private int nextPageNo;//下一页

    private int totalPages;//总页数
    private int startIndex;//当前页起始记录的索引编号

    private List<T>list;//分页显示的集合

    private String keyWords;//关键词

    public Pagination() {
    }


    public Pagination(int totalRecords, int maxRows, int currPageNo, int prePageNo, int nextPageNo, int totalPages, int startIndex, List<T> list, String keyWords) {
        this.totalRecords = totalRecords;
        this.maxRows = maxRows;
        this.currPageNo = currPageNo;
        this.prePageNo = prePageNo;
        this.nextPageNo = nextPageNo;
        this.totalPages = totalPages;
        this.startIndex = startIndex;
        this.list = list;
        this.keyWords = keyWords;
    }

    public int getTotalRecords() {
        return totalRecords;
    }

    public void setTotalRecords(int totalRecords) {
        this.totalRecords = totalRecords;
    }

    public int getMaxRows() {
        return maxRows;
    }

    public void setMaxRows(int maxRows) {
        this.maxRows = maxRows;
    }

    public int getCurrPageNo() {
        return currPageNo;
    }

    public void setCurrPageNo(int currPageNo) {
        this.currPageNo = currPageNo;
    }

    public int getPrePageNo() {
        if (currPageNo>=2&&currPageNo<=getTotalPages()){
            prePageNo=currPageNo-1;
        }else {
            prePageNo=-1;
        }
        return prePageNo;
    }

    public void setPrePageNo(int prePageNo) {
        this.prePageNo = prePageNo;
    }

    public int getNextPageNo() {
        if (currPageNo>=1&&currPageNo<getTotalPages()){
            nextPageNo=currPageNo+1;
        }else {
            nextPageNo=-1;
        }
        return nextPageNo;
    }

    public void setNextPageNo(int nextPageNo) {
        this.nextPageNo = nextPageNo;
    }

    public int getTotalPages() {
        if(maxRows==-1||maxRows==0)
            maxRows=totalRecords;
        totalPages=(totalRecords%maxRows==0)?totalRecords/maxRows:totalRecords/maxRows+1;
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getStartIndex() {
        if (currPageNo>=1&&currPageNo<=getTotalPages()){
            startIndex=(currPageNo-1)*maxRows;
        }else {
            startIndex=0;
        }
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public String getKeyWords() {
        return keyWords;
    }

    public void setKeyWords(String keyWords) {
        this.keyWords = keyWords;
    }
}
